﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Views.Catalogs.Distritos;
using Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModelBase;
using System.Globalization;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Resources;

namespace Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModels.Catalogs.Distritos
{
	/// <summary>
	/// 
	/// </summary>
	public partial class DistritosViewModel
		: ObservableObject
	{

		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private DistritosView _distritosView;

		#endregion

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritosView"></param>
		public DistritosViewModel(DistritosView distritosView)
		{
			if (distritosView == null)
				throw new ArgumentNullException("distritosView");
			_distritosView = distritosView;
			WireUpEvents();
			InitModels();
		}

		#endregion

		#region Event methods

		/// <summary>
		/// 
		/// </summary>
		private void WireUpEvents()
		{
			PropertyChanged += DistritosViewModel_PropertyChanged;
			_distritosView.Load += LoadView;
			_distritosView.bindingNavigatorDeleteItem.Click += DeleteDistrito;
			_distritosView.bindingNavigatorAddNewItem.Click += AddNewDistrito;
			_distritosView.newButton.Click += AddNewDistrito;
			_distritosView.distritoBindingNavigatorSaveItem.Click += SaveDistrito;
			_distritosView.saveButton.Click += SaveDistrito;
			_distritosView.closeButton.Click += (sender, e) =>
			{
				_distritosView.Close();
			};
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void LoadView(object sender, EventArgs e)
		{
			_distritosView.Text = string.Format(
				CultureInfo.InvariantCulture,
				WindowTitles.DistritosWindowTitle
			);
		}

		#endregion

		#region Private methods

		/// <summary>
		/// 
		/// </summary>
		private void InitModels()
		{
			LoadEstados();
			LoadEstadosDistrito();
			LoadCiclos();
		}

		/// <summary>
		/// 
		/// </summary>
		private void StartWaiting()
		{
			_distritosView.WaitingBar.StartWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void EndWaiting()
		{
			_distritosView.WaitingBar.EndWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void FocusDefaultControl()
		{
			_distritosView.ActiveControl = _distritosView.nombreUltraTextEditor;
		}

		#endregion

	}
}
